package com.ruoyi.business.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.business.MyPage;
import com.ruoyi.business.PageConfig;
import com.ruoyi.business.Visit;
import com.ruoyi.business.mapper.VisitMapper;
import com.ruoyi.business.qo.VisitQO;
import com.ruoyi.business.vo.VisitVO;
import com.ruoyi.common.common.ResultBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * @author ：jiangguanjun
 * @description：网站浏览记录
 * @date ：2020/7/16 21:13
 */
@Slf4j
@Component
public class VisitService {

    @Autowired
    VisitMapper visitMapper;


    public int save(Visit visit) {
        return visitMapper.insertSelective(visit);
    }

    public ResultBody queryPage(VisitQO visitQO) {
        MyPage myPage = PageConfig.getPage();
        log.info("myPage:::{}",myPage);
        Page<VisitVO> page = new Page<>(myPage.getPageNum(), myPage.getPageSize());
        IPage<VisitVO> visitVOListPage = visitMapper.queryPage(page,visitQO) ;

        visitVOListPage.getRecords().forEach(visitVO -> {
            visitVO.setCPullName(visitVO.getCParentName()+"-"+visitVO.getCName());
        });

        return ResultBody.success(visitVOListPage) ;
    }
}
